﻿#region
/*******************************************************************************
** File Name:		    WarehouseService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class WarehouseService : IWarehouseService
    {
		 IWarehouse warehouse = new WarehouseRepository();
		 
		 #region  Auto Generation
		 

	
		public IList<WarehouseModel> GetAll ()
		{
			IList<EWarehouse> entity = warehouse.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<WarehouseModel> list = new List<WarehouseModel>();

            foreach (var item in entity)
            {
                WarehouseModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private WarehouseModel ConvertEntityToModel(EWarehouse entity)
		{
			if (entity == null)
            {
                return null;
            }
			WarehouseModel model = new WarehouseModel();
                        model.WarehouseID = entity.WarehouseID;
                        model.Name = entity.Name;
                        model.Code = entity.Code;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EWarehouse ConvertModelToEntity(WarehouseModel model)
		{
			if (model == null)
            {
                return null;
            }
			EWarehouse entity = new EWarehouse();
                        entity.WarehouseID = model.WarehouseID;
                        entity.Name = model.Name;
                        entity.Code = model.Code;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}